package com.fzy.common.filter;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPOutputStream;

/**
 * 网页文件流压缩操作
 */
public class GZIPServletStream extends ServletOutputStream {
    private GZIPOutputStream outputStream;

    @Override
    public boolean isReady() {
        return false;
    }

    @Override
    public void setWriteListener(WriteListener writeListener) {

    }

    public GZIPServletStream(OutputStream source) throws IOException {
        outputStream = new GZIPOutputStream(source);
    }

    public void finish() throws IOException {
        outputStream.finish();
    }

    @Override
    public void write(byte[] buf) throws IOException {
        outputStream.write(buf);
    }

    @Override
    public void write(byte[] buf, int off, int len) throws IOException {
        outputStream.write(buf, off, len);
    }

    @Override
    public void write(int c) throws IOException {
        outputStream.write(c);
    }

    @Override
    public void flush() throws IOException {
        outputStream.flush();
    }

    @Override
    public void close() throws IOException {
        outputStream.close();
    }

}
